package battlecruiser.shooter.reader;

import battlecruiser.board.cell.coordinate.Coordinate;

import java.io.IOException;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Simulates an input from user. For unit-tests only.
 *
 * @author Yakiv Tymoshenko
 * @since 05.09.12
 */
public class StringTargetReader extends TargetReader {

    private StringTokenizer targetCoordinatesTokens;

    public StringTargetReader() {
    }


    @Override
    public Coordinate readTarget() throws IOException {
        System.out.print("Input target coordinate: ");
        Coordinate result = null;
        if (targetCoordinatesTokens.hasMoreTokens()) {
            result = new Coordinate(targetCoordinatesTokens.nextToken());
        }
        System.out.println(result);
        return result;
    }

    @Override
    public Coordinate selectRandomNeighbourOnTheSameLine(List<Coordinate> damagedDecks) throws IOException {
        return null;
    }

    @Override
    public Coordinate selectRandomNeighbour(Coordinate coordinate) throws IOException {
        return null;
    }

    public void readAllTargets(String multipleTargetsAsString) {
        targetCoordinatesTokens = new StringTokenizer(multipleTargetsAsString, "\n");
    }
}
